#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string minWindow(string s, string t)
    {
        string ret;
        int ret_size = INT_MAX, begin = -1;
        long long hash1[128] = { 0 };
        int kinds = 0;//统计有效字符多少种
        for (auto e : t)
        {
            if (hash1[e]++ == 0) kinds++;
        }
        long long hash2[128] = { 0 };
        for (int left = 0, right = 0, count = 0; right < s.size(); right++)
        {
            //进窗口
            char in = s[right];
            hash2[in]++;
            if (hash2[in] == hash1[in]) count++;

            while (count == kinds)
            {
                //更新结果
                if (ret_size > right - left + 1)
                {
                    ret_size = right - left + 1;
                    begin = left;
                }
                //出窗口
                char out = s[left];
                if (hash2[out] == hash1[out]) count--;
                hash2[out]--;
                left++;
            }
        }
        if (begin == -1) return "";
        return s.substr(begin, ret_size);
    }
};

class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words)
    {
        vector<int> ret;
        unordered_map<string, int> hash1;
        for (auto word : words)
        {
            hash1[word]++;
        }
        int len = words[0].size(), m = words.size();
        for (int i = 0; i < len; i++)//循环进行滑动窗口
        {
            unordered_map<string, int> hash2;
            for (int left = i, right = i, count = 0; right + len <= s.size(); right += len)
            {
                string in = s.substr(right, len);
                hash2[in]++;
                if (hash2[in] <= hash1[in]) count++;

                if (right - left + 1 > m * len)
                {
                    string out = s.substr(left, len);
                    if (hash2[out] <= hash1[out]) count--;
                    hash2[out]--;
                    left += len;
                }
                if (count == m)
                {
                    ret.push_back(left);
                }
            }
        }
        return ret;
    }
};